Skip to content

fix(desktop): discover nvm-managed Node in the App tool search - #9184

Open
xiaods wants to merge 5 commits into
loopx-project:mainfrom
xiaods:codex/desktop-nvm-node-search
Open

xiaods wants to merge 5 commits into
loopx-project:mainfrom
xiaods:codex/desktop-nvm-node-search

Conversation

@xiaods

@xiaods xiaods commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On macOS, launching LoopX Desktop from Finder fails runtime preparation with:

安装程序退出(1);App 的启动环境未找到 Node.js。请启用受支持的 Node.js 后点击「修复当前版本」。

Diagnostics show node_found: false on a host whose only supported Node is
installed with nvm (~/.nvm/versions/node/v24.22.1/bin/node).

Finder/launchd never load a user's interactive shell profile, so the App
resolves tools from a bounded search path (runtime_search_path in
src-tauri/src/services.rs): $HOME/.local/bin, Homebrew, the keg-only
node@24/node@22 formulae, then the inherited PATH. nvm activates Node by
prepending $NVM_BIN to the interactive PATH, so that activation is invisible
to a GUI launch: the private installer ran
loopx doctor --deep --installation-only with no Node on PATH, the
typescript_effect_runtime_ready check failed, and install-local.sh exited 1.
The installed 2.3.0 binary contains the Homebrew entries but no .nvm string,
confirming the shipped search never considered nvm.

Reproduced locally with the App's own search path:

$ PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:...:/usr/bin:/bin" \
    loopx --format json doctor --deep --installation-only
"typescript_effect_runtime_ready": ok=false, "detected_node_version": null,
"diagnostic_code": "node_unavailable"          # exit 1

Fix

Resolve the same bounded nvm locations the Lark CLI resolver
(loopx/extensions/lark/cli_resolution.py) already uses, without running nvm
or sourcing any startup file:

  1. $NVM_BIN activated in the App's own environment (a terminal launch),
  2. the recorded default alias chain (default -> lts/* ->
    lts/krypton -> v24.22.1),
  3. the installed versions newest-first, behind the supported Homebrew
    runtimes so an outdated default cannot hide them.

The alias read stays inside $NVM_DIR/alias, is depth-bounded and rejects
non-normal path components, so a missing, cyclic or malformed chain just falls
through to installed-version discovery. The installer and the App-owned
services share this single search path, so the services started afterwards
also see the same Node.

Validation

  • cargo test --lib (206 passed): four new tests cover alias-chain resolution
    and escape rejection, NVM_BIN precedence, newest-first installed versions,
    PATH ordering/idempotency, and NVM_DIR/HOME root selection. The existing
    Finder tool-search test gained an ambient-NVM_BIN guard so an nvm-activated
    developer shell cannot break its fixed-position assertions.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings clean.
  • Windows cfg gating verified by compiling the added block with and without
    the unix cfg (rustc), so the Windows CI leg cannot regress.
  • python3 -m unittest discover -s tests/desktop (28 passed).
  • Real-path check with the installed App's private release: the same doctor
    command above returns ok=true, detected_node_version: 24.22.1 once the
    search path can reach nvm-managed Node.
  • loopx canary premerge --from-git-diff --git-diff-base main (standard tier):
    passed selected=17 failures=0.

Scope / remaining gaps

  • Hosts whose Node comes from another version manager (fnm, asdf, volta, n)
    still rely on $HOME/.local/bin, Homebrew or a terminal launch; nvm is the
    evidenced gap here and the fix stays bounded to it.
  • The shipped 2.3.0 binary is unaffected; this needs a new signed desktop
    build/release. Affected users can work around it today with
    ln -s ~/.nvm/versions/node/<version>/bin/node ~/.local/bin/node, which the
    current search path already honors.

fixed issue #9133

Finder and launchd never load a user's interactive shell profile, so the
desktop App resolves its tools from a bounded search path. That search
covered Homebrew and `$HOME/.local/bin` but not nvm, which activates Node
by prepending `$NVM_BIN` to the interactive PATH. On a host whose only
supported Node is nvm-managed, the private installer therefore ran
`loopx doctor --deep --installation-only` without a Node on PATH, the
TypeScript runtime check failed, and the installer exited 1 — surfaced as
"安装程序退出(1);App 的启动环境未找到 Node.js" with `node_found: false`.

Resolve the same bounded nvm locations the Lark CLI resolver already uses,
without running nvm or sourcing any startup file: an `NVM_BIN` activated in
the App's own environment, then the recorded `default` alias chain
(`default` -> `lts/*` -> `lts/krypton` -> `v24.22.1`), then the installed
versions newest-first behind the supported Homebrew runtimes. The alias
read stays inside `$NVM_DIR/alias`, is depth-bounded and rejects
non-normal path components, so a missing, cyclic or malformed chain simply
falls through to installed-version discovery.

The installer and the App-owned services share this one search path, so the
same fix also covers the services the App starts afterwards.

Signed-off-by: Xiao Deshi <[email protected]>
@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Validation evidence (head 4df48e7b7)

Pre-merge gate (standard tier, diff against main):

[loopx canary] premerge start: tier=standard changed_files=4 surfaces=docs_project_content, public_boundary
[loopx canary] premerge done: passed selected=17 failures=0
Gate Result
cargo test --lib 206 passed, 12 ignored (4 new nvm tests)
cargo fmt --check clean
cargo clippy --all-targets -- -D warnings clean
Windows cfg gating added block compiles with and without the unix cfg (rustc), so the Windows CI leg cannot regress
python3 -m unittest discover -s tests/desktop 28 passed
Real path (installed App's private release) loopx --format json doctor --deep --installation-only under the App's search path: before ok=false, detected_node_version=null, diagnostic_code=node_unavailable, exit 1; after the fix ok=true, detected_node_version=24.22.1, exit 0

Note: services::supervisor_tests::connected_runtime_requires_both_healthy_exact_identity_listeners is intermittently flaky (AddrInUse from ServiceEndpoints::allocate dropping its reservation between tests) on unmodified main as well — reproduced 1 failure in 5 base runs — so it is unrelated to this change.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

从 Finder 启动或修复 LoopX Desktop、同时装有多个 Node 版本的 macOS 用户。 现有发现依赖共享工具搜索,只有 nvm 的用户从 Finder 启动时找不到 Node。 原问题 Finder 环境下,未设置 NVM_BIN 时,旧 nvm default 指向 Node 20,机器同时有合格 Homebrew Node。基线 doctor 退出 0,当前头退出 1,TypeScript runtime 检查报告 unsupported。 提案让安装器和 App 服务发现 nvm 的激活路径、记录默认 alias 和已安装版本,避免读取交互 shell。 本次范围是工具发现与诊断,签名 App 发布和其他版本管理器支持需分别验证。

改动思路 / Approach

在桌面端原有共享路径统一解决 nvm 发现是合理的,兼容版本由 Core 的 Node 探测验收。 保留单一共享搜索入口,新增 nvm 回退时保持旧的可用启动路径。 自动发现的旧 alias 可以作为候选,需在使用前资格校验或放到现有合格入口之后。终端显式激活的语义需要单列。

具体改动 / Changes

逐项检查当前头 4df48e7 和 merge base 00ef1c7,3 个文件,+270/-3。Rust 增加版本目录排序与别名链解析,目录探测有深度和路径组件限制。PATH 给安装器和已有服务统一消费,诊断由同一次搜索拿到二进制。核对了共享搜索与受支持运行时两项。README 同步发现优先级,新测试覆盖路径、排序和别名回退。 目标基线的契约

关键代码讲解

  • activated_nvm_directories 给显式 NVM_BIN 和磁盘 default 生成路径,runtime_search_path 将这两组一起放在 Homebrew 前。 路径构造
  • Core 的 probe_node 使用 PATH 上第一个 Node 做版本校验,因此排在后面的健康路径无法恢复。 版本校验
  • 改动附带 Rust 路径和别名测试,需加入两种安装并存时的真实资格断言。 现有测试

对主干的风险 / Risks

[P1] 旧 nvm 默认版本遮蔽合格 Homebrew Node。 Finder 环境下,未设置 NVM_BIN 时,旧 nvm default 指向 Node 20,机器同时有合格 Homebrew Node。基线 doctor 退出 0,当前头退出 1,TypeScript runtime 检查报告 unsupported。 把自动推断的 alias 与显式 NVM_BIN 分开处理,确保自动发现不能遮蔽机器上合格的既有候选,再按两套 Node 验收首次安装和既有实例修复。 当前行为会使原已具备受支持 Node 的 Finder 用户进入准备失败或修复失败。旧版本使用仅响应版本查询的本地夹具,健康 Node 为真实 Homebrew 可执行文件,两个 Rust arm 共享同一 doctor。

本地编译准确基线与当前头的原 Rust PATH 生成函数,分别接同一个已安装 LoopX 的 doctor --deep --installation-only。无 alias、有效 default、显式有效 NVM_BIN 和无效 alias 回退四组均通过,Python 桌面测试 28 项通过。 Quick premerge 的四项直接与四项选定检查均通过。首次 Cargo 缺少打包资源。生成准确头的 runtime bundle 后重跑,四个 nvm 用例中三项过,一项失败。已选默认目录又被已安装目录遍历加入 PATH,导致 Finder 路径顺序断言失败。 已安装的签名 App、Windows/Linux 启动、远端 CI 均未验证。现有结果来自源码函数与实际 Core 资格命令组合。

我的整体评价 / Verdict

请求修改。在桌面端原有共享路径统一解决 nvm 发现是合理的,兼容版本由 Core 的 Node 探测验收。 保留单一共享搜索入口,新增 nvm 回退时保持旧的可用启动路径。 可用系统 Node 被旧 alias 遮蔽的回归仍可复现。 请补齐同机存在旧默认与受支持 Node 的正常入口测试及全路径去重,再交新头。

English verdict: REQUEST_CHANGES at 4df48e7. An inferred stale nvm default breaks Finder-style preparation despite a qualified Homebrew Node. The base/head PATH and real doctor differential confirms the regression.

…ates

Review of the first head found a regression: an inferred nvm `default`
alias was placed ahead of the Homebrew runtimes, so a Finder launch on a
host with a stale nvm default (Node 20) plus a qualified Homebrew Node
moved from `doctor` exit 0 to exit 1 — the App preferred the stale
inferred candidate over a Node the host already provided.

Split the two kinds of nvm location:

- an `NVM_BIN` the launching shell exported stays first, which only
  preserves the precedence the inherited PATH already gave a
  terminal-launched App, and
- everything this App discovers on disk — the recorded `default` alias,
  then the installed versions newest-first — is appended last, behind
  Homebrew and the inherited PATH, so automatic discovery extends the
  search for a host that has no other Node and never displaces one that
  does.

Deduplicate the whole search path, so a directory discovered twice (an
activated version that is also the recorded default, or an inherited entry
this App also adds) appears once, and keep the search idempotent.

Tests pin the nvm inputs through `runtime_search_path_from` instead of
mutating the process environment that parallel tests read, and add the
reviewer's scenario as a real qualification oracle: a stale inferred
default beside a supported Node resolves to the supported one, while the
same stale default stays discoverable when nothing else provides a Node.

Differential against the installed App's private release, same doctor
command and search path:

| scenario | base | head |
| --- | --- | --- |
| qualified Node + stale nvm default | exit 0, node 24.22.1 | exit 0, node 24.22.1 |
| nvm-only, stale default v20 | exit 1, node unavailable | exit 1, node 20.18.0 reported |
| nvm-only, supported default v24 | exit 1, node unavailable | exit 0, node 24.22.1 |

Signed-off-by: Xiao Deshi <[email protected]>
@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

已按评审修改 / Changes addressing the review

新头 dd43091f0(原 4df48e7b7 + 1 commit)。P1 接受并已修复,同时补上你指出的去重与"两种安装并存"的真实资格断言。

P1:推断出的旧 nvm default 遮蔽合格 Homebrew Node — 已修复

把两类 nvm 位置分开,只有"启动 shell 导出的激活"保留原优先级,其余全部降为最后候选:

顺序 候选 理由
1 $HOME/.local/bin 不变
2 显式 NVM_BIN(nvm use / 终端启动) 只是保留继承 PATH 本来已有的优先级:终端启动时 nvm 本来就排在 PATH 最前,基线行为不变
3 /opt/homebrew/bin、/usr/local/bin、node@24/node@22 keg 原有受支持入口
4 继承 PATH 终端启动带入的既有候选
5 推断:default 别名链 自动发现,最后候选
6 推断:其余已装版本(新→旧) 自动发现,最后候选

即:自动发现只会为"本机没有其他 Node"的主机补齐能力,永不顶替主机已有的 Node;旧 default 不再让原本 doctor 退出 0 的 Finder 用户变成退出 1。

全路径去重 — 已修复

你遇到的"已选默认目录又被已安装目录遍历加入 PATH"是因为两组各自去重、彼此没有。现在统一走 extend_unique,整条搜索路径每个目录只出现一次(激活版本同时也是 default / 已装版本时也只出现一次),并保持幂等。测试中断言 unique.len() == paths.len()、default 目录计数为 1、二次调用结果相同。

同机"旧 default + 受支持 Node"正常入口测试 — 已补齐

inferred_nvm_default_cannot_shadow_an_existing_qualified_node 用真实可执行文件做资格判定(不是只比路径):夹具里放旧 default v20.18.0 和一个受支持 v24.22.1,resolve_executable_path("node", …) 必须解析到受支持那个,并实跑 --version 校验;反向再断言"本机没有其他 Node 时,旧 default 仍然可被发现"(nvm 不变成不可见)。

另外测试改为通过 runtime_search_path_from(home, inherited, nvm_root, nvm_bin) 注入 nvm 输入,不再改进程环境变量,避免与并行测试互相干扰(你那次"Finder 路径顺序断言失败"有一部分来自环境变量串扰)。

用你同一套 oracle 复跑的 base/head 差异

同一台已安装 App 的私有 release、同一条 loopx --format json doctor --deep --installation-only、同一份搜索路径(head 尾部追加推断出的 nvm 目录):

场景 base head
A. 受支持 Node 存在 + 旧 nvm default v20(你的回归) exit 0, node 24.22.1 exit 0, node 24.22.1
B. 只有 nvm、旧 default v20 exit 1, node 不可用 exit 1, node 20.18.0(诊断更准确,未新增失败)
C. 只有 nvm、supported default v24.22.1(原 issue) exit 1, node 不可用 exit 0, node 24.22.1

A 的回归已消除,C 的原始问题已修复。

验证汇总(头 dd43091f0)

  • cargo fmt --check 干净;cargo clippy --all-targets -- -D warnings 干净
  • cargo test --lib:207 passed(nvm/Finder 相关 6 项,连跑 3 次全绿)
  • Windows cfg 门:新增块分别以「有 / 无 unix cfg」用 rustc 编译通过(函数参数上的 #[cfg] 也覆盖),Windows CI leg 不会回归
  • python3 -m unittest discover -s tests/desktop:28 passed
  • loopx canary premerge --from-git-diff --git-diff-base main(standard):passed selected=17 failures=0

遗留说明(非本次引入):services::supervisor_tests::connected_runtime_requires_both_healthy_exact_identity_listeners 在未改动的 main 上也会偶发 AddrInUse(ServiceEndpoints::allocate 在两次 bind 之间丢掉预留端口),我在基线上 5 次里复现过 1 次,与本次改动无关。

English summary: the P1 is fixed by separating an exported NVM_BIN (explicit activation, keeps the precedence the inherited PATH already had) from everything inferred on disk (default alias, then installed versions newest-first), which is now appended behind Homebrew and the inherited PATH; the whole search path is deduplicated and idempotent; a real qualification oracle test covers stale-inferred-default beside a supported Node, and the base/head doctor differential shows scenario A back to exit 0 while the original nvm-only scenario now exits 0.

The CI macOS runner ships a real Node at /opt/homebrew/bin, so the
regression test's assumption that the fixture provides the only qualified
candidate was wrong there: resolution legitimately picked the runner's
Homebrew Node and the test failed.

Assert the rule instead of a specific winner. For a given search path,
resolve `node` and check whether any non-nvm candidate exists on this host:
when one does, the resolved executable must not be the inferred stale
default and must not come from the nvm tree; when none does, the inferred
default is the only candidate and must still resolve. The ordering
guarantee behind that resolution is asserted directly, so every non-nvm
entry — including the Homebrew entries this App adds — precedes the
inferred one.

Verified locally both with and without a simulated /opt/homebrew/bin/node,
which is the environment the runner provides.

Signed-off-by: Xiao Deshi <[email protected]>
@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

CI 修复 / CI fix

新头 4bd3bf871(上一个头 dd43091f0 + 1 commit,只改测试)。

validate 失败是我新加的测试 oracle 写错了,不是产品代码问题:GitHub 的 macOS runner 自带 /opt/homebrew/bin/node(真实 Node),所以"夹具提供唯一合格候选"这个假设在 runner 上不成立——解析正确地落到了 runner 的 Homebrew Node 上,测试却断言必须等于夹具里的那个。

改为断言规则而不是某个赢家:对同一条搜索路径解析 node,先看本机是否存在非 nvm 候选——

  • 存在 → 解析结果不得是推断出的旧 default,且不得来自 nvm 目录树;
  • 不存在 → 旧 default 是唯一候选,必须仍能解析到(nvm 不会变成不可见)。

同时直接断言背后的顺序保证:所有非 nvm 条目(含 App 自己追加的 Homebrew 条目)都排在推断条目之前。

我在本地按 runner 的环境两种都验证过:临时造一个 /opt/homebrew/bin/node 前后,nvm/Finder 相关 6 项连跑均通过;完整 cargo test --lib 207 passed。

当前头验证汇总(4bd3bf871):

  • cargo fmt --check 干净;cargo clippy --all-targets -- -D warnings 干净
  • cargo test --lib:207 passed / 12 ignored(含 /opt/homebrew/bin/node 存在与不存在两种主机形态)
  • python3 -m unittest discover -s tests/desktop:28 passed
  • loopx canary premerge --from-git-diff --git-diff-base main(standard):passed selected=17 failures=0

English: the validate failure came from my new test assuming the fixture held the only qualified Node, which is false on the GitHub macOS runner (it ships a real /opt/homebrew/bin/node). The test now asserts the invariant — an inferred stale nvm default is never selected while any non-nvm candidate exists, and is still selected when none does — and the ordering guarantee behind it. Verified locally with and without a simulated /opt/homebrew/bin/node; full suite 207 passed, canary premerge 17/0.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

从 Finder 启动、由终端打开或修复桌面 App 的 macOS 操作者,包括机器上并存多个 Node 候选的用户。 安装器和 App 服务共享受限工具 PATH。已有的 Homebrew 和继承 PATH Node 可满足安装资格。 终端环境保留指向 Node 20 的 NVM_BIN,但当前 PATH 选择受支持的 Node。分别让旧目录不在 PATH,或排在有效 Node 之后。实际 Rust PATH 交给同一真实 doctor,基线两组都退出 0;当前头两组都把旧目录提前,doctor 退出 1 并报告 unsupported。 当前增加 nvm 发现。区分导出的激活和磁盘推断,再由已有 doctor 验证 Node。 改动限于候选发现和启动资格。签名 App、发布及其他版本管理器需分别验收。

改动思路 / Approach

桌面共享搜索负责候选顺序,Core doctor 负责校验首个候选的版本和实际运行。 复用现有搜索和真实版本资格。基于继承 PATH 判明是否应提升导出的环境变量,保持 Finder 回退和正常终端优先级。 核验当前提交对上一处旧磁盘 alias 和重复目录的修复,再通过同一 doctor 对照继承 PATH 与 NVM_BIN 搭配失配的两组环境。

具体改动 / Changes

逐项检查当前头 4bd3bf8 和 merge base 00ef1c7,3 个文件,+495/-25。RUNTIME-FINDER-DISCOVERY 和 RUNTIME-DEDUP 已验证。RUNTIME-TERMINAL-PATH 的真实支持 Node 被提升变量遮蔽。RUNTIME-PORTABLE-TEST 的新 Unix 断言在非 macOS 路径不成立。 评审依据为 Issue #9133,2026-11-21 读回。 目标规范

关键代码讲解

  • 环境来源与共享路径 将显式环境先于 macOS 候选和继承 PATH,磁盘推断置尾。
  • Core 资格检查 读取首个 Node 就地探测。旧变量有实体目录也不证明它是当前 shell 所选的 Node。
  • 新平台测试 改用实际候选判定,但 Unix 通用顺序断言列出了只在 macOS 添加的固定目录。

对主干的风险 / Risks

[P2] 残留 NVM_BIN 会覆盖终端已选的受支持 Node。 终端环境保留指向 Node 20 的 NVM_BIN,但当前 PATH 选择受支持的 Node。分别让旧目录不在 PATH,或排在有效 Node 之后。实际 Rust PATH 交给同一真实 doctor,基线两组都退出 0;当前头两组都把旧目录提前,doctor 退出 1 并报告 unsupported。 判断 NVM_BIN 是否仍与实际继承的 Node 选择一致,再保留已有优先级。无一致证据时把这个路径当回退,避免改变已有的受支持 Node。保留真实激活、Finder 只有 nvm 和重复路径三个对照。 这一环境下旧程序可以使用合格的 Homebrew 或 PATH Node,升级后的安装与修复入口会报版本不支持。

[P2] Unix 测试要求 macOS 专属路径。 新测试在所有 Unix 平台执行,循环却要求六个只由 macOS 分支加入的目录。用当前源码选择非 macOS 分支,六个目录均缺失,查找位置的断言会失败。请仅在 macOS 核对这些路径,在所有 Unix 保留继承 PATH 与 nvm 的通用顺序断言。

当前头已修复上轮 Finder 反例。没有 NVM_BIN 时,旧磁盘 default 让位于有效 Homebrew Node。仅有 nvm 且默认版本受支持的隔离主机从 missing 转为 ready。真正有效的终端激活仍通过,候选目录去重。 准确头打包资源通过,macOS cargo fmt 及 cargo test --lib 通过(207 passed)。28 项 Python 桌面测试与 quick premerge 的 4 项直接、4 项选定检查通过。 实测组合为准确提交 Rust 路径和已安装 Core 的本机 doctor,未启动候选签名 App。非 macOS 分支在本机 Rust 夹具验证路径断言,未实际运行 Linux 或 Windows 构建。

我的整体评价 / Verdict

请求修改。桌面共享搜索负责候选顺序,Core doctor 负责校验首个候选的版本和实际运行。 复用现有搜索和真实版本资格。基于继承 PATH 判明是否应提升导出的环境变量,保持 Finder 回退和正常终端优先级。 终端资格应继续根据真实选择决定,Unix 上新测试还须保持平台隔离。 前轮的磁盘 default 问题已修复。请补齐终端残留变量和非 macOS Unix 的同入口验证。

English verdict: REQUEST_CHANGES at 4bd3bf8. A stale NVM_BIN still overrides the supported Node selected by the inherited PATH. The new Unix regression test also unconditionally requires six macOS-only paths. The prior stale inferred default is fixed.

@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Windows 检查说明 / Note on the red Windows check

windows-desktop-tests 失败的是 service_lifecycle::windows_update_tests::a_verified_artifact_whose_launch_fails_keeps_the_window_usable_and_returns_the_runtime(src/service_lifecycle_windows_update_tests.rs:261),报错是 loopback feed 的 reqwest 竞态:

the loopback feed answers: Reqwest(reqwest::Error { kind: Request,
  url: "http://127.0.0.1:53592/feed.json", source: ... Error(Canceled,
  hyper::Error(Canceled, "connection was not ready")) })

这与本次改动无关,且是既有 flake:

  • 同一测试在未改动的 main 上同样失败过:run 44174196059(2026-11-17,windows-desktop-tests job),失败测试、文件行号(:261)、7 passed; 1 failed 与错误文本完全一致。
  • 本次改动全部位于 #[cfg(unix)] 门内;Windows leg 编译通过(同一 job 里其余 7 个测试全绿,Windows desktop 构建 leg 也 pass),失败发生在测试自建的 loopback HTTP fixture 竞态上。
  • 我没有该仓库的 admin 权限,无法 gh run rerun --failed 重跑这个 job;下面用关闭再打开 PR 的方式触发一次全新的 CI 运行来验证。

English: the single red check is a pre-existing flaky Windows-only test (a_verified_artifact_whose_launch_fails_keeps_the_window_usable_and_returns_the_runtime, service_lifecycle_windows_update_tests.rs:261) whose loopback update feed loses a reqwest race. The identical test, line and failure text already failed on unmodified main (run 44174196059). My change is entirely #[cfg(unix)]-gated, the Windows leg compiled and its other 7 tests passed. Re-triggering CI below for a fresh sample.

@xiaods xiaods closed this Nov 21, 2026
@xiaods xiaods reopened this Nov 21, 2026
Review of the second head found a second precedence regression: an
`NVM_BIN` the launching shell exported was always promoted ahead of the
inherited PATH, so a terminal that had put a supported Node first after
`nvm use` still resolved the stale Node 20 directory and moved `doctor`
from exit 0 to exit 1.

An exported activation is now authoritative only while it still agrees
with the Node the inherited PATH selects: no Node there, or the same
executable nvm activated. Otherwise the shell moved on and left the
variable behind, so the directory drops to the last resort — behind the
discovered `default` alias and the installed versions, which also keeps a
newer install ahead of it.

Also gate the macOS-only Homebrew entries in the Unix tests behind
`cfg(target_os = "macos")`: those six directories are only added by the
macOS branch of the search, so asserting them on every Unix platform
failed on non-macOS sources. The generic inherited-PATH versus nvm
ordering assertions stay for all Unix.

Differential against the installed App's private release, same doctor
command and search path:

| scenario | base | previous head | this head |
| --- | --- | --- | --- |
| stale NVM_BIN v20, PATH selects v24 | exit 0, node 24.22.1 | exit 1, node 20.18.0 | exit 0, node 24.22.1 |
| activation still matches PATH | exit 0, node 24.22.1 | exit 0 | exit 0, node 24.22.1 |
| stale default alias + qualified Node | exit 0, node 24.22.1 | exit 0 | exit 0, node 24.22.1 |
| nvm-only, supported Node | exit 1, unavailable | exit 0 | exit 0, node 24.22.1 |

Disclosed residual case: a host whose only Node is nvm-managed and whose
`default` alias predates the supported minimum while a newer version is
installed resolves the recorded default first. That is the user's own
recorded choice and Core still qualifies the version, so the App reports
the real version instead of a missing Node; `nvm alias default` moves it.

Signed-off-by: Xiao Deshi <[email protected]>
@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

第二轮 P2 已修复 / Second-round P2 findings addressed

新头 c11b46656(上一头 4bd3bf871 + 1 commit)。

P2 #1:残留 NVM_BIN 覆盖终端已选的受支持 Node — 已修复

规则改成"导出的激活只有在仍然与 PATH 实际选中的 Node 一致时才有权威":

  • 继承 PATH 里没有 Node,或它解析到的就是 nvm 激活的那个可执行文件 → NVM_BIN 保持原位(第 2 位,终端启动的既有优先级);
  • 否则说明 shell 已经换过 Node、只留下旧变量 → 该目录降为最后候选,排在发现的 default 别名和已装版本之后(更新的已装版本也排在它前面)。

用你同一套 oracle 复跑(已安装 App 私有 release、同一 doctor、同一份 Rust 搜索路径):

场景 base 上一头 本头
残留 NVM_BIN→v20,PATH 选 v24 exit 0, node 24.22.1 exit 1, node 20.18.0 exit 0, node 24.22.1
激活仍与 PATH 一致(真实激活) exit 0, node 24.22.1 exit 0 exit 0, node 24.22.1
旧 default 别名 + PATH 上合格 Node(上轮 P1) exit 0, node 24.22.1 exit 0 exit 0, node 24.22.1
只有 nvm、受支持版本 exit 1, unavailable exit 0 exit 0, node 24.22.1

三个对照都保留:真实激活、Finder 只有 nvm、重复路径去重(Rust 层断言 unique.len() == paths.len()、目录计数为 1、幂等)。

残留情况(明确披露,不算回归):只有 nvm、default 别名旧于受支持下限、但同时装了更新版本的主机,会优先用记录在案的 default。这是用户自己记录的选择,版本仍由 Core 验收,App 会报告真实版本而非"找不到 Node";nvm alias default 即可切换。没有把版本阈值复制进 App。

P2 #2:Unix 测试要求 macOS 专属路径 — 已修复

那六个 Homebrew 条目只有 cfg!(target_os = "macos") 分支才会加入搜索路径,原先在所有 Unix 上断言它们的存在,在非 macOS 源码下必然失败。现在:

  • macOS 专属条目用 #[cfg(target_os = "macos")] 收进断言列表;
  • 所有 Unix 保留通用顺序断言:~/.local/bin、继承 PATH 条目相对 nvm 推断条目的先后。

验证汇总(头 c11b46656)

  • cargo fmt --check 干净;cargo clippy --all-targets -- -D warnings 干净
  • cargo test --lib:207 passed / 12 ignored(nvm/Finder/stale 相关 11 项连跑全绿)
  • Windows cfg 门:新增块分别以「有 / 无 unix cfg」用 rustc 编译并通过运行
  • python3 -m unittest discover -s tests/desktop:28 passed
  • loopx canary premerge --from-git-diff --git-diff-base main(standard):passed selected=17 failures=0

既有 flake(非本次引入,前面已记录):connected_runtime_requires_both_healthy_exact_identity_listeners 的 AddrInUse,单独运行通过。

English: P2 #1 is fixed by making an exported NVM_BIN authoritative only while it still agrees with the Node the inherited PATH selects (no Node there, or the same executable); otherwise it is demoted behind the discovered default alias and installed versions. P2 #2 is fixed by asserting the six Homebrew entries only on macOS while keeping the generic inherited-PATH versus nvm ordering assertions on all Unix. The base/previous-head/this-head doctor differential shows the stale-NVM_BIN case back to exit 0, with real activation, Finder-nvm-only and duplicate-path controls unchanged.

The CI macOS runner ships a real Node at /opt/homebrew/bin, which the
search ranks ahead of the inherited PATH. The new test therefore resolved
that Node instead of the fixture's selected one and failed on the runner
while passing locally.

Assert the rule, not a specific winner: with a host candidate present the
resolved Node must be that candidate, and only when none exists may a
demoted `NVM_BIN` be selected at all. The PATH-order guarantees (an
agreeing activation at position 1, a demoted one behind the selected Node
and behind the newer installed version) stay host-independent.

Verified locally with and without a simulated /opt/homebrew/bin/node.

Signed-off-by: Xiao Deshi <[email protected]>
@xiaods

xiaods commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

CI 二次修复 / Second CI fix

新头 f3ad36a0c(上一头 c11b46656 + 1 commit,仍只改测试)。

validate 又红在我新加的测试 oracle 上,理由和上一次同类:GitHub macOS runner 自带 /opt/homebrew/bin/node,而这条静态条目排在继承 PATH 之前,所以"解析结果必须等于夹具里那个 selected Node"在 runner 上不成立。

改成断言规则:给定搜索路径先解析 node——

  • 本机存在非 nvm 候选(夹具的 selected 目录,或 runner 的 /opt/homebrew/bin)→ 解析结果必须就是它;
  • 本机没有非 nvm 候选时,降级的 NVM_BIN 才可以被选中(此时 nvm 树里的 default/已装版本排在它前面,所以仍然不是它)。

PATH 顺序保证(一致的激活在第 1 位、降级的激活排在 selected Node 与更新已装版本之后)本来就是主机无关的,保持不变。

本地在"有 / 无模拟 /opt/homebrew/bin/node"两种主机形态下各连跑 3 次,nvm/Finder/stale 相关 11 项全绿;完整 cargo test --lib 207 passed。

当前头验证汇总(f3ad36a0c):

  • cargo fmt --check 干净;cargo clippy --all-targets -- -D warnings 干净
  • cargo test --lib:207 passed / 12 ignored(含 runner 形态)
  • python3 -m unittest discover -s tests/desktop:28 passed
  • loopx canary premerge --from-git-diff --git-diff-base main(standard):passed selected=17 failures=0

上一轮 CI 里 windows-desktop-tests 已经 pass(那个 Windows flake 没有复现,进一步印证它与本改动无关);本轮的 macOS desktop / Windows desktop 均 pass。

English: the second validate failure was the same class of oracle bug — the runner's real /opt/homebrew/bin/node ranks ahead of the inherited PATH, so asserting the fixture's selected Node wins was wrong there. The test now asserts the rule: with a host candidate present, resolution must be that candidate; only without one may a demoted NVM_BIN be selected. Verified in both host shapes locally; full suite 207 passed, canary premerge 17/0, and the previously flaky Windows check passed on the last run.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

只装 nvm 的 macOS 用户从 Finder 启动或恢复 Desktop 时需要可用的 Node 运行时。 Desktop 共享的工具 PATH 发现 Homebrew 和终端继承目录。单独安装 nvm 的 Finder 环境可能不包含这些 Node。 模拟没有 Homebrew 或继承 Node 的 Finder 启动,未导出 NVM_BIN,nvm 目录里同时保留 Node 20 默认版本与受支持的 Node 24。精确头将 Node 20 放在首位。实际 doctor 退出 1,TypeScript runtime 检查失败;合格的 Node 24 明明已经被发现,却排在后面。 当前精确头增加 nvm 候选发现并保留自动推断、显式 NVM_BIN、继承工具优先级。上一轮残留变量和非 macOS 断言已有对应修复。 独立验证 Mac 源码、实际安装版 Core doctor、PATH 合成隔离和普通测试。无 Homebrew 场景通过剔除固定系统候选模拟。未安装或签名候选 App,未执行 Linux/Windows App。

改动思路 / Approach

Desktop Rust 负责定位和传递同一个 PATH。Core 仍负责通过实际运行判断 Node 资格。 同一发现入口供当前 App 安装器与其拥有的服务调用。无 shell 初始化或机器配置写入。 在自动推断的候选路径中保留首个满足现行资格的 Node,用已有 Core 的版本规则,避免重复维护阈值。真实终端激活保持单独处理。

具体改动 / Changes

逐项检查当前头 f3ad36a 和 merge base 00ef1c7,3 个文件,+614/-25。核对 finder-discovery、terminal-first-node、platform-gating、qualified-nvm-fallback 四项。前三项当前角度通过;最后一项仍欠有并存版本时的已支持 Node 选择。源码显示二者均加入 PATH,实际失败发生在 Core 选择首个可执行文件时。 评审依据为 Issue #9133 与当前头 Desktop README 的 Finder tool discovery。 目标规范

关键代码讲解

  • nvm 目录顺序 先加入磁盘记录的默认,再加入所有排序版本,即使默认无法满足 Core 的最低版本。
  • Runtime readiness 只探测 PATH 中选中的首个可执行 Node。后续目录无法被此入口读取。
  • 测试 验证主机已有 Node 的优先级。精确头未覆盖仅 nvm 且已安装另一个受支持版本的情况。

对主干的风险 / Risks

[P2] 仅安装 nvm 时旧 default 会遮蔽可用 Node。 模拟没有 Homebrew 或继承 Node 的 Finder 启动,未导出 NVM_BIN,nvm 目录里同时保留 Node 20 默认版本与受支持的 Node 24。精确头将 Node 20 放在首位。实际 doctor 退出 1,TypeScript runtime 检查失败;合格的 Node 24 明明已经被发现,却排在后面。 保留原有显式 NVM_BIN 和主机候选顺序,通过现有 Core 版本资格在推断的 nvm 候选中选可用项。默认 alias 不满足时,继续检查已发现的后续版本,再注入这次启动的有效入口。 受影响用户已有可运行版本,却仍在原本要修复的 Finder 安装或修复入口失败。

用精确头 Rust PATH 连接实际安装版 Core doctor。受支持的 Homebrew Node 在旧默认 alias 下继续可用;残留 NVM_BIN 在终端有效 PATH 下也让位。仅有 nvm 时,受支持的默认版本与无效 alias 两个对照从基线缺 Node 变为可用。 macOS Cargo 207 项通过、12 项明确忽略,28 项 Python 桌面测试及 quick premerge 通过。当前头 Rust 路径和真实 doctor 的五组配对验证包含一个独立失败对照。 独立验证 Mac 源码、实际安装版 Core doctor、PATH 合成隔离和普通测试。无 Homebrew 场景通过剔除固定系统候选模拟。未安装或签名候选 App,未执行 Linux/Windows App。

我的整体评价 / Verdict

请求修改。Desktop Rust 负责定位和传递同一个 PATH。Core 仍负责通过实际运行判断 Node 资格。 同一发现入口供当前 App 安装器与其拥有的服务调用。无 shell 初始化或机器配置写入。 当前能发现目录,但第一条路径仍可能使整个安装资格失败。 请补齐仅有 nvm、旧默认与支持版本并存的实际启动资格。上一轮的终端和平台修复可保留。 已验证 Rust PATH 到真实安装资格的结果。 候选号签名 App 的完整启动未测试。

English verdict: REQUEST_CHANGES at f3ad36a. The earlier stale NVM_BIN and platform assertions are addressed. On an nvm-only host, the inferred unsupported default still masks a supported installed Node and the real installation doctor fails.

#[cfg(unix)]
fn discovered_nvm_directories(nvm_root: &Path, demoted_nvm_bin: Option<&Path>) -> Vec<PathBuf> {
let mut directories = Vec::new();
if let Some(version) = resolve_nvm_alias(nvm_root, "default", 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 仅安装 nvm 时旧 default 会遮蔽可用 Node。模拟没有 Homebrew 或继承 Node 的 Finder 启动,未导出 NVM_BIN,nvm 目录里同时保留 Node 20 默认版本与受支持的 Node 24。精确头将 Node 20 放在首位。实际 doctor 退出 1,TypeScript runtime 检查失败;合格的 Node 24 明明已经被发现,却排在后面。 保留原有显式 NVM_BIN 和主机候选顺序,通过现有 Core 版本资格在推断的 nvm 候选中选可用项。默认 alias 不满足时,继续检查已发现的后续版本,再注入这次启动的有效入口。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants